
package vip.xiaonuo.biz.modular.lancerGoodskill.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.common.pojo.CommonValidList;
import vip.xiaonuo.biz.modular.lancerGoodskill.entity.BizGoodsKill;
import vip.xiaonuo.biz.modular.lancerGoodskill.param.BizGoodsKillAddParam;
import vip.xiaonuo.biz.modular.lancerGoodskill.param.BizGoodsKillEditParam;
import vip.xiaonuo.biz.modular.lancerGoodskill.param.BizGoodsKillIdParam;
import vip.xiaonuo.biz.modular.lancerGoodskill.param.BizGoodsKillPageParam;
import vip.xiaonuo.biz.modular.lancerGoodskill.service.BizGoodsKillService;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;

/**
 * 秒杀控制器
 *
 * @author Lancer
 * @date  2024/03/03 17:01
 */
@Api(tags = "秒杀控制器(管理端)")
@ApiSupport(author = "LANCER_TEAM", order = 1)
@RestController
@Validated
public class AdminGoodsKillController {

    @Resource
    private BizGoodsKillService bizGoodsKillService;

    /**
     * 获取秒杀分页
     *
     * @author Lancer
     * @date  2024/03/03 17:01
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation("管理端获取秒杀分页")
    @SaCheckPermission("/biz/admin/goodskill/page")
    @GetMapping("/biz/admin/goodskill/page")
    public CommonResult<Page<BizGoodsKill>> page(BizGoodsKillPageParam bizGoodsKillPageParam) {
        return CommonResult.data(bizGoodsKillService.page(bizGoodsKillPageParam));
    }

    /**
     * 添加秒杀
     *
     * @author Lancer
     * @date  2024/03/03 17:01
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation("管理端添加秒杀")
    @CommonLog("添加秒杀")
    @SaCheckPermission("/biz/admin/goodskill/add")
    @PostMapping("/biz/admin/goodskill/add")
    public CommonResult<String> add(@RequestBody @Valid BizGoodsKillAddParam bizGoodsKillAddParam) {
        bizGoodsKillService.add(bizGoodsKillAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑秒杀
     *
     * @author Lancer
     * @date  2024/03/03 17:01
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation("管理端编辑秒杀")
    @CommonLog("编辑秒杀")
    @SaCheckPermission("/biz/admin/goodskill/edit")
    @PostMapping("/biz/admin/goodskill/edit")
    public CommonResult<String> edit(@RequestBody @Valid BizGoodsKillEditParam bizGoodsKillEditParam) {
        bizGoodsKillService.edit(bizGoodsKillEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除秒杀
     *
     * @author Lancer
     * @date  2024/03/03 17:01
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation("管理端删除秒杀")
    @CommonLog("删除秒杀")
    @SaCheckPermission("/biz/admin/goodskill/delete")
    @PostMapping("/biz/admin/goodskill/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   CommonValidList<BizGoodsKillIdParam> bizGoodsKillIdParamList) {
        bizGoodsKillService.delete(bizGoodsKillIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取秒杀详情
     *
     * @author Lancer
     * @date  2024/03/03 17:01
     */
    @ApiOperationSupport(order = 5)
    @ApiOperation("管理端获取秒杀详情")
    @SaCheckPermission("/biz/admin/goodskill/detail")
    @GetMapping("/biz/admin/goodskill/detail")
    public CommonResult<BizGoodsKill> detail(@Valid BizGoodsKillIdParam bizGoodsKillIdParam) {
        return CommonResult.data(bizGoodsKillService.detail(bizGoodsKillIdParam));
    }
}
